package logic

import (
	"context"
	"hzjt-oam/rpc/sys/internal/svc"
	"hzjt-oam/rpc/sys/model"
	"hzjt-oam/rpc/sys/pb"
	"time"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddSysUserLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddSysUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddSysUserLogic {
	return &AddSysUserLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// -----------------------用户管理-----------------------
func (l *AddSysUserLogic) AddSysUser(in *pb.AddSysUserReq) (*pb.AddSysUserResp, error) {
	var sys_user = &model.SysUser{
		Name:           in.Name,
		NickName:       in.NickName,
		Avatar:         in.Avatar,
		Password:       in.Password,
		Salt:           in.Salt,
		Email:          in.Email,
		Mobile:         in.Mobile,
		Status:         in.Status,
		DeptId:         in.DeptId,
		CreateBy:       in.CreateBy,
		CreateTime:     time.Now().Unix(),
		LastUpdateBy:   in.LastUpdateBy,
		LastUpdateTime: in.LastUpdateTime,
		DelFlag:        0,
		RoleId:         in.RoleId,
	}

	_, err := l.svcCtx.UserModel.Insert(l.ctx, sys_user)

	if err != nil {
		return nil, err
	}

	return &pb.AddSysUserResp{}, nil
}
